package cn.edu.scau.liangshanhero.actions;

import java.io.File;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import cn.edu.scau.liangshanhero.configurateUtf8Filter.WebXMLConfigureUTF8FilterByDOM;
import cn.edu.scau.liangshanhero.util.ProjectContext;

public class ConfigureUTF8FilterAction implements
		IWorkbenchWindowActionDelegate {

	private IWorkbenchWindow window;
	private File webXMLFile;

	@Override
	public void run(IAction action) {
		// System.out.println("UTF8过滤器插件开始运行...");
		Shell shell = new Shell();
		MessageDialog.openInformation(shell,
				"Add UTF8 Encoding Filter to Web.xml",
				"Add UTF8 Encoding Filter to Web.xml");
		// MessageDialog.openInformation(window.getShell(),"ConfigureUTF8FilterAction","ConfigureUTF8FilterAction");
		// 第一步：确定选择的项目 的配置文件
		// 注意了，myeclipse中对的web.xml是在webroot目录下，其他的web项目是在webcontent目录下，有所不同

//		webXMLFile = new File(ProjectContext.getCurrentProject().getLocation()				+ "/WebRoot/WEB-INF/web.xml");
		// 第二步：在项目的配置文件web.xml中插入spring过滤器

		// MessageDialog.openInformation(window.getShell(),"ConfigureUTF8FilterAction","ConfigureUTF8FilterAction");

		// MessageDialog.openInformation(shell,
		// "Add UTF8 Encoding Filter to Web.xml", webXMLFile.toString());

//		WebXMLConfigureUTF8FilterByDOM.UpdateWebXMLUTF8(webXMLFile);
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init(IWorkbenchWindow window) {
		MessageDialog.openConfirm(window.getShell(),
				"Initialing the UTF-8 Filter", "UTF-8 Filter");
		// MessageDialog.openInformation(window.getShell(),"ConfigureUTF8FilterAction","ConfigureUTF8FilterAction");
	}

}
